import request from '@/utils/request';
import { praseStrEmpty } from "@/utils/rock";

// 查询用户列表
export function apiListUser(query) {
  return request({
    url: '/system/user/list',
    method: 'get',
    params: query
  });
}

// 查询用户详细
export function apiGetUser(userId) {
  return request({
    url: '/system/user/' + praseStrEmpty(userId),
    method: 'get'
  });
}

// 新增用户
export function apiAddUser(data) {
  return request({
    url: '/system/user',
    method: 'post',
    data: data
  });
}

// 修改用户
export function apiUpdateUser(data) {
  return request({
    url: '/system/user',
    method: 'put',
    data: data
  });
}

// 删除用户
export function apiDelUser(userId) {
  return request({
    url: '/system/user/' + userId,
    method: 'delete'
  });
}

// 导出用户
export function apiExportUser(query) {
  return request({
    url: '/system/user/export',
    method: 'get',
    params: query
  });
}

// 用户密码重置
export function apiResetUserPwd(userId, password) {
  const data = {
    userId,
    password
  };
  return request({
    url: '/system/user/resetPwd',
    method: 'put',
    data: data
  });
}

// 用户状态修改
export function apiChangeUserStatus(userId, status) {
  const data = {
    userId,
    status
  };
  return request({
    url: '/system/user/changeStatus',
    method: 'put',
    data: data
  });
}

// 查询用户个人信息
export function apiGetUserProfile() {
  return request({
    url: '/system/user/profile',
    method: 'get'
  });
}

// 修改用户个人信息
export function apiUpdateUserProfile(data) {
  return request({
    url: '/system/user/profile',
    method: 'put',
    data: data
  });
}

// 用户密码重置
export function apiUpdateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword
  };
  return request({
    url: '/system/user/profile/updatePwd',
    method: 'put',
    params: data
  });
}

// 用户头像上传
export function apiUploadAvatar(data) {
  return request({
    url: '/system/user/profile/avatar',
    method: 'post',
    data: data
  });
}

// 下载用户导入模板
export function apiImportTemplate() {
  return request({
    url: '/system/user/importTemplate',
    method: 'get'
  });
}
